package com.github.gaojh.mvc.route;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author gaojh
 * @since 2020/3/24
 */
@Slf4j
public class FlyingRouter implements Router {

    private static final ConcurrentHashMap<String, RouteInfo> ROUTE_MAP = new ConcurrentHashMap<>();

    @Override
    public void addRouteInfo(RouteInfo routeInfo) {
        log.debug("注册路由：{} ===> {}", routeInfo.getRequestPath(), routeInfo.getType().getName() + "." + routeInfo.getMethod().getName());
        ROUTE_MAP.put(routeInfo.getRequestPath(), routeInfo);
    }

    @Override
    public RouteInfo getRouteInfo(String requestPath) {
        return ROUTE_MAP.get(requestPath);
    }
}
